
% pops up a figure with the image and allows user to select arbitrary
% number of vessel segments

function [r,imsz,msk] = selectVesselCenters(im,figtitle,plotcolor,fighandle)

if nargin < 3 || isempty(plotcolor)
    plotcolor = 'parula';
end
linesegs = [];
if nargin < 4 || isempty(fighandle)
    figure;
else
    figure(fighandle)
end
imax = axes;
imagesc(im);colormap(plotcolor);
if nargin > 1 && ~isempty(figtitle)
    title(figtitle)
end
axis equal
msk = false(size(im));
while true
    curline = drawpolyline(imax);
    s = input('keep line and finish: 1\nkeep line and continue selecting: 2\ndiscard line and continue: 3\ndiscard line and finish: 4\n');
    while isempty(s) || s > 4
        s = input('keep line and finish: 1\nkeep line and continue selecting: 2\ndiscard line and continue: 3\ndiscard line and finish: 4\n');
    end
    switch s
        case 1
            linesegs = [linesegs, curline];
            msk = msk | createMask(curline);
            break;
        case 2
            linesegs = [linesegs, curline];
            msk = msk | createMask(curline);
        case 3
            set(curline,'Visible','off');
            continue;
        case 4
            set(curline,'Visible','off');
            break;
    end
end
r = cell(size(linesegs));
for n = 1:length(r)
    r{n} = linesegs(n).Position;
end
imsz = size(im);

